package com.internetCafes.spms.web.certificate.entity;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.internetCafes.spms.common.CommonConstants;
import com.internetCafes.spms.common.utils.DateUtils;
import com.internetCafes.spms.core.utils.CharUtil;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.Date;


/**
 * 证书借还历史
 *
 * @author Sunny
 * @email rekeeper2011@hotmail.com
 * @date 2019-11-28 14:04:13
 */
@Data
public class CertiTransactionInfo implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 本表ID
     */
    private Long id;

    /**
     * 租户id
     */
    private Long tenantId;

    /**
     * 证书ID
     */
    private Long certificateId;

    /**
     * 类型:11挂入,12归还,21挂出,22收回,31借出,32还回
     */
    private Integer type;

    /**
     * 挂出人
     */
    private Long affiliationEmployee;

    /**
     * 挂出人
     */
    private String affiliationEmployeeName;

    /**
     * 原单位ID
     */
    private Long fromDeptId;

    /**
     * 原单位名称
     */
    private String fromDeptName;

    /**
     * 原保管人ID
     */
    private Long fromUserId;

    /**
     * 原保管人名称
     */
    private String fromUserName;

    /**
     * 原单位保管人电话
     */
    private String fromUserMobile;

    /**
     * 接管单位ID
     */
    private Long toDeptId;

    /**
     * 接管单位名称
     */
    private String toDeptName;

    /**
     * 接管人ID
     */
    private Long toUserId;

    /**
     * 接管人名称
     */
    private String toUserName;

    /**
     * 接管人联系电话
     */
    private String toUserMobile;

    /**
     * 备注信息
     */
    private String remark;

    /**
     * 接管时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date transactionTime;

    /**
     * 返还时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date transactionEndTime;
    /**
     * 创建者
     */
    private Long createBy;

    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date createTime;

    /**
     * 更新人
     */
    private Long updateBy;

    /**
     * 更新时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date updateTime;

    /**
     * 挂靠收入
     */
    private Double affiliationIncome;

    /**
     * 挂靠支出
     */
    private Double affiliationExpend;

    /**
     * 是否通过中介
     */
    private Integer agencyFlag;

    /**
     * 中介名称
     */
    private String agencyName;

    /**
     * 中介费用
     */
    private Double agencyFee;

    /**
     * 其他费用
     */
    private Double otherFee;

    /**
     * 费用说明
     */
    private String feeRemark;

    /**
     * 是否支付:1是，0否
     */
    private Integer payFlag;

    /**
     * 支付时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date payTime;

    /**
     * 是否交税:1税前,0税后
     */
    private Integer tax;

    /**
     * 挂出使用情况
     * 与证书状态对应
     * BID_USED(21, "投标"),
     * PROJECT_USED(22, "项目"),
     * BID_SUCCESS(23, "中标"),
     * OTHER_STATUS(24, "其他"),
     */
    private Integer usage;

    /**
     * 项目名称
     */
    private String projectName;

    /**
     * 押证标签 1是 0 否 默认为1
     */
    private Integer warrantFlag;

    /**
     * 当前流转记录状态
     *
     * 0 -进行中  1- 已结束
     */
    private Integer statusTag;

    /**
     * 借出押人标签 0-否 1-是
     */
    private Integer detaineeFlag;

    /**
     * 归还来自id
     */
    private Long returnFromId;

    /**
     * 项目id
     */
    private Long projectId;

    public CertiTransactionInfo() {
    }

    public CertiTransactionInfo(Long tenantId, Long certificateId, Integer type, Long fromDeptId, String fromDeptName, Long fromUserId, String fromUserName, String fromUserMobile, Long toDeptId, String toDeptName, Long toUserId, String toUserName, String toUserMobile, String remark, Date transactionTime, Long createBy, Date createTime) {
        this.tenantId = tenantId;
        this.certificateId = certificateId;
        this.type = type;
        this.fromDeptId = fromDeptId;
        this.fromDeptName = fromDeptName;
        this.fromUserId = fromUserId;
        this.fromUserName = fromUserName;
        this.fromUserMobile = fromUserMobile;
        this.toDeptId = toDeptId;
        this.toDeptName = toDeptName;
        this.toUserId = toUserId;
        this.toUserName = toUserName;
        this.toUserMobile = toUserMobile;
        this.remark = remark;
        this.transactionTime = transactionTime;
        this.createBy = createBy;
        this.createTime = createTime;
    }

    public CertiTransactionInfo(Long tenantId, Long certificateId, Integer type, String fromDeptName, String fromUserName, String fromUserMobile, Long toDeptId, String toDeptName, Long toUserId, String toUserName, String toUserMobile, String remark, Date transactionTime) {
        this.tenantId = tenantId;
        this.certificateId = certificateId;
        this.type = type;
        this.fromDeptName = fromDeptName;
        this.fromUserName = fromUserName;
        this.fromUserMobile = fromUserMobile;
        this.toDeptId = toDeptId;
        this.toDeptName = toDeptName;
        this.toUserId = toUserId;
        this.toUserName = toUserName;
        this.toUserMobile = toUserMobile;
        this.remark = remark;
        this.transactionTime = transactionTime;
    }

    public CertiTransactionInfo(String toDeptName, String toUserName, String toUserMobile, Date transactionTime, Date transactionEndTime) {
        this.toDeptName = toDeptName;
        this.toUserName = toUserName;
        this.toUserMobile = toUserMobile;
        this.transactionTime = transactionTime;
        this.transactionEndTime = transactionEndTime;
    }

    public CertiTransactionInfo(Long tenantId, Long certificateId, Integer type, Long fromDeptId, String fromDeptName, Long fromUserId, String fromUserName, Long toDeptId, String toDeptName, Long toUserId, String toUserName, String toUserMobile, String remark, Date transactionTime) {
        this.tenantId = tenantId;
        this.certificateId = certificateId;
        this.type = type;
        this.fromDeptId = fromDeptId;
        this.fromDeptName = fromDeptName;
        this.fromUserId = fromUserId;
        this.fromUserName = fromUserName;
        this.toDeptId = toDeptId;
        this.toDeptName = toDeptName;
        this.toUserId = toUserId;
        this.toUserName = toUserName;
        this.toUserMobile = toUserMobile;
        this.remark = remark;
        this.transactionTime = transactionTime;
    }

    public CertiTransactionInfo(String toDeptName, String toUserName, String toUserMobile, String remark, Date transactionTime, Date transactionEndTime, double affiliationIncome, double agencyFee, double otherFee, String feeRemark, Integer payFlag, Date payTime, Integer tax) {
        this.toDeptName = toDeptName;
        this.toUserName = toUserName;
        this.toUserMobile = toUserMobile;
        this.remark = remark;
        this.transactionTime = transactionTime;
        this.transactionEndTime = transactionEndTime;
        this.affiliationIncome = affiliationIncome;
        this.agencyFee = agencyFee;
        this.otherFee = otherFee;
        this.feeRemark = feeRemark;
        this.payFlag = payFlag;
        this.payTime = payTime;
        this.tax = tax;
    }

    public Date getTransactionEndTime() {
        return transactionEndTime;
    }

    @JSONField(name = "transaction_end_time")
    public void setTransactionEndTime(Date transactionEndTime) {
        this.transactionEndTime = transactionEndTime;
    }

    public Integer getTax() {
        return tax;
    }

    public void setTax(Integer tax) {
        this.tax = tax;
    }

    public Double getAffiliationIncome() {
        return affiliationIncome;
    }

    @JSONField(name = "affiliation_income")
    public void setAffiliationIncome(Double affiliationIncome) {
        this.affiliationIncome = affiliationIncome;
    }

    public Double getAffiliationExpend() {
        return affiliationExpend;
    }

    @JSONField(name = "affiliation_expend")
    public void setAffiliationExpend(Double affiliationExpend) {
        this.affiliationExpend = affiliationExpend;
    }

    public Integer getAgencyFlag() {
        return agencyFlag;
    }

    @JSONField(name = "agency_flag")
    public void setAgencyFlag(Integer agencyFlag) {
        this.agencyFlag = agencyFlag;
    }

    public String getAgencyName() {
        return agencyName;
    }

    @JSONField(name = "agency_name")
    public void setAgencyName(String agencyName) {
        this.agencyName = agencyName;
    }

    public Double getAgencyFee() {
        return agencyFee;
    }

    @JSONField(name = "agency_fee")
    public void setAgencyFee(Double agencyFee) {
        this.agencyFee = agencyFee;
    }

    public Double getOtherFee() {
        return otherFee;
    }

    @JSONField(name = "other_fee")
    public void setOtherFee(Double otherFee) {
        this.otherFee = otherFee;
    }

    public String getFeeRemark() {
        return feeRemark;
    }

    @JSONField(name = "fee_remark")
    public void setFeeRemark(String feeRemark) {
        this.feeRemark = feeRemark;
    }

    public Integer getPayFlag() {
        return payFlag;
    }

    @JSONField(name = "pay_flag")
    public void setPayFlag(Integer payFlag) {
        this.payFlag = payFlag;
    }

    public Date getPayTime() {
        return payTime;
    }

    @JSONField(name = "pay_time")
    public void setPayTime(Date payTime) {
        this.payTime = payTime;
    }

    @JSONField(name = "id")
    public void setId(Long id) {
        this.id = id;
    }

    public Long getId() {
        return id;
    }

    @JSONField(name = "tenant_id")
    public void setTenantId(Long tenantId) {
        this.tenantId = tenantId;
    }

    public Long getTenantId() {
        return tenantId;
    }

    @JSONField(name = "certificate_id")
    public void setCertificateId(Long certificateId) {
        this.certificateId = certificateId;
    }

    public Long getCertificateId() {
        return certificateId;
    }

    @JSONField(name = "type")
    public void setType(Integer type) {
        this.type = type;
    }

    public Integer getType() {
        return type;
    }

    @JSONField(name = "from_dept_id")
    public void setFromDeptId(Long fromDeptId) {
        this.fromDeptId = fromDeptId;
    }

    public Long getFromDeptId() {
        return fromDeptId;
    }

    @JSONField(name = "from_dept_name")
    public void setFromDeptName(String fromDeptName) {
        this.fromDeptName = fromDeptName;
    }

    public String getFromDeptName() {
        return fromDeptName;
    }

    @JSONField(name = "from_user_id")
    public void setFromUserId(Long fromUserId) {
        this.fromUserId = fromUserId;
    }

    public Long getFromUserId() {
        return fromUserId;
    }

    @JSONField(name = "from_user_name")
    public void setFromUserName(String fromUserName) {
        this.fromUserName = fromUserName;
    }

    public String getFromUserName() {
        return fromUserName;
    }

    @JSONField(name = "from_user_mobile")
    public void setFromUserMobile(String fromUserMobile) {
        this.fromUserMobile = fromUserMobile;
    }

    public String getFromUserMobile() {
        return fromUserMobile;
    }

    @JSONField(name = "to_dept_id")
    public void setToDeptId(Long toDeptId) {
        this.toDeptId = toDeptId;
    }

    public Long getToDeptId() {
        return toDeptId;
    }

    @JSONField(name = "to_dept_name")
    public void setToDeptName(String toDeptName) {
        this.toDeptName = toDeptName;
    }

    public String getToDeptName() {
        return toDeptName;
    }

    @JSONField(name = "to_user_id")
    public void setToUserId(Long toUserId) {
        this.toUserId = toUserId;
    }

    public Long getToUserId() {
        return toUserId;
    }

    @JSONField(name = "to_user_name")
    public void setToUserName(String toUserName) {
        this.toUserName = toUserName;
    }

    public String getToUserName() {
        return toUserName;
    }

    @JSONField(name = "to_user_mobile")
    public void setToUserMobile(String toUserMobile) {
        this.toUserMobile = toUserMobile;
    }

    public String getToUserMobile() {
        return toUserMobile;
    }

    @JSONField(name = "remark")
    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getRemark() {
        return remark;
    }

    @JSONField(name = "transaction_time")
    public void setTransactionTime(Date transactionTime) {
        this.transactionTime = transactionTime;
    }

    public Date getTransactionTime() {
        return transactionTime;
    }

    @JSONField(name = "create_by")
    public void setCreateBy(Long createBy) {
        this.createBy = createBy;
    }

    public Long getCreateBy() {
        return createBy;
    }

    @JSONField(name = "create_time")
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getCreateTime() {
        return createTime;
    }

    @JSONField(name = "update_by")
    public void setUpdateBy(Long updateBy) {
        this.updateBy = updateBy;
    }

    public Long getUpdateBy() {
        return updateBy;
    }

    @JSONField(name = "update_time")
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public String getRandomNum() {
        return CharUtil.getRandomString(6);
    }

    public Integer getUsage() {
        return usage;
    }

    public void setUsage(Integer usage) {
        this.usage = usage;
    }

    public String getProjectName() {
        return projectName;
    }

    public void setProjectName(String projectName) {
        this.projectName = projectName;
    }

    public Integer getWarrantFlag() {
        return warrantFlag;
    }

    public void setWarrantFlag(Integer warrantFlag) {
        this.warrantFlag = warrantFlag;
    }

    public Integer getStatusTag() {
        return statusTag;
    }

    public void setStatusTag(Integer statusTag) {
        this.statusTag = statusTag;
    }

    public Integer getDetaineeFlag() {
        return detaineeFlag;
    }

    public void setDetaineeFlag(Integer detaineeFlag) {
        this.detaineeFlag = detaineeFlag;
    }

    public Long getReturnFromId() {
        return returnFromId;
    }

    public void setReturnFromId(Long returnFromId) {
        this.returnFromId = returnFromId;
    }

    @Override
    public String toString() {
        return "记录时间:" + DateUtils.format(transactionTime) + "，" +
                "原保管单位：" + fromDeptName + "，" +
                "原保管人：" + fromUserName + (StringUtils.isNotBlank(fromUserMobile) ? "(" + fromUserMobile + ")，" : "，") +
                "保管单位：" + toDeptName + "，" +
                "保管人：" + toUserName + (StringUtils.isNotBlank(fromUserMobile) ? "(" + toUserMobile + ")，" : "，") +
                "备注:" + (StringUtils.isNotBlank(remark) ? remark + "；" : "无；");
    }

    /**
     * 证书还回数据记录创建封装
     *
     * @param transactionOutInfo 对应借出记录
     * @param createBy           创建人
     * @param createTime         创建时间
     * @param remark             备注
     * @author Zj
     */
    public void transactionReturnInfoCopy(CertiTransactionInfo transactionOutInfo, Long createBy, Date createTime, String remark, Date transactionEndTime) {
        this.setTransactionTime(transactionEndTime);
        this.setRemark(remark);
        this.setCreateTime(createTime);
        this.setCreateBy(createBy);
        this.setStatusTag(CommonConstants.CertiTransactionStatusTags.COMPLETE.getTag());
        this.setType(CommonConstants.CertiTransactionInfoType.Transaction_Return);
        this.setReturnFromId(transactionOutInfo.getId());
        this.setFromDeptName(transactionOutInfo.getToDeptName());
        this.setFromDeptId(transactionOutInfo.getToDeptId());
        this.setFromUserName(transactionOutInfo.getToUserName());
        this.setFromUserId(transactionOutInfo.getToUserId());
        this.setFromUserMobile(transactionOutInfo.getToUserMobile());
        this.setFromDeptName(transactionOutInfo.getToDeptName());
        this.setFromUserName(transactionOutInfo.getToUserName());
        this.setFromUserMobile(transactionOutInfo.getToUserMobile());
        this.setToDeptName(transactionOutInfo.getFromDeptName());
        this.setToUserName(transactionOutInfo.getFromUserName());
        this.setToDeptId(transactionOutInfo.getFromDeptId());
        this.setToUserId(transactionOutInfo.getFromUserId());
        this.setToUserMobile(transactionOutInfo.getFromUserMobile());
    }
}
